# -*- coding: utf-8 -*-

"""
# @version: v1.0
# @author : Wlis
# @Email : 19688513@qq.com
# @Project : py-stock_-app
# @File : stock_base.py
# @Software: PyCharm
# @time: 2024/4/5 10:41
# @description : A股父类
"""
from datetime import datetime




class StockBase:
    def __init__(self, _id, code, name, latest_price, change_percent, change_amount, volume, turnover, amplitude,
                 high, low, open_price, prev_close, volume_ratio, turnover_rate, dynamic_pe_ratio, pb_ratio,
                 total_market_value, circulating_market_value, increase_speed, five_minute_change, sixty_day_change,
                 year_to_date_change, creation_time=None):
        """
        中国股票模型类

        Args:
            _id (int): 股票的唯一标识符
            code (str): 股票代码
            name (str): 股票名称
            latest_price (float): 最新价
            change_percent (float): 涨跌幅
            change_amount (float): 涨跌额
            volume (float): 成交量
            turnover (float): 成交额
            amplitude (float): 振幅
            high (float): 最高价
            low (float): 最低价
            open_price (float): 今开盘价
            prev_close (float): 昨收盘价
            volume_ratio (float): 量比
            turnover_rate (float): 换手率
            dynamic_pe_ratio (float): 市盈率-动态
            pb_ratio (float): 市净率
            total_market_value (float): 总市值
            circulating_market_value (float): 流通市值
            increase_speed (float): 涨速
            five_minute_change (float): 5分钟涨跌
            sixty_day_change (float): 60日涨跌幅
            year_to_date_change (float): 年初至今涨跌幅
        """

        self.id = _id  # 添加 ID 属性
        self.code = code
        self.name = name
        self.latest_price = latest_price
        self.change_percent = change_percent
        self.change_amount = change_amount
        self.volume = volume
        self.turnover = turnover
        self.amplitude = amplitude
        self.high = high
        self.low = low
        self.open_price = open_price
        self.prev_close = prev_close
        self.volume_ratio = volume_ratio
        self.turnover_rate = turnover_rate
        self.dynamic_pe_ratio = dynamic_pe_ratio
        self.pb_ratio = pb_ratio
        self.total_market_value = total_market_value
        self.circulating_market_value = circulating_market_value
        self.increase_speed = increase_speed
        self.five_minute_change = five_minute_change
        self.sixty_day_change = sixty_day_change
        self.year_to_date_change = year_to_date_change
        # 添加创建时间
        if creation_time is None:
            self.creation_time = datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
        else:
            self.creation_time = creation_time

    def get_id(self):
        return self.id

    def set_id(self, _id):
        self.id = _id

    # Getter方法
    def get_code(self):
        """
        获取股票代码

        Returns:
            str: 股票代码
        """
        return self.code

    def get_name(self):
        """
        获取股票名称

        Returns:
            str: 股票名称
        """
        return self.name

    def get_latest_price(self):
        """
        获取最新价

        Returns:
            float: 最新价
        """
        return self.latest_price

    def get_change_percent(self):
        """
        获取涨跌幅

        Returns:
            float: 涨跌幅
        """
        return self.change_percent

    def get_change_amount(self):
        """
        获取涨跌额

        Returns:
            float: 涨跌额
        """
        return self.change_amount

    def get_volume(self):
        """
        获取成交量

        Returns:
            float: 成交量
        """
        return self.volume

    def get_turnover(self):
        """
        获取成交额

        Returns:
            float: 成交额
        """
        return self.turnover

    def get_amplitude(self):
        """
        获取振幅

        Returns:
            float: 振幅
        """
        return self.amplitude

    def get_high(self):
        """
        获取最高价

        Returns:
            float: 最高价
        """
        return self.high

    def get_low(self):
        """
        获取最低价

        Returns:
            float: 最低价
        """
        return self.low

    def get_open_price(self):
        """
        获取今开盘价

        Returns:
            float: 今开盘价
        """
        return self.open_price

    def get_prev_close(self):
        """
        获取昨收盘价

        Returns:
            float: 昨收盘价
        """
        return self.prev_close

    def get_volume_ratio(self):
        """
        获取量比

        Returns:
            float: 量比
        """
        return self.volume_ratio

    def get_turnover_rate(self):
        """
        获取换手率

        Returns:
            float: 换手率
        """
        return self.turnover_rate

    def get_dynamic_pe_ratio(self):
        """
        获取市盈率-动态

        Returns:
            float: 市盈率-动态
        """
        return self.dynamic_pe_ratio

    def get_pb_ratio(self):
        """
        获取市净率

        Returns:
            float: 市净率
        """
        return self.pb_ratio

    def get_total_market_value(self):
        """
        获取总市值

        Returns:
            float: 总市值
        """
        return self.total_market_value

    def get_circulating_market_value(self):
        """
        获取流通市值

        Returns:
            float: 流通市值
        """
        return self.circulating_market_value

    def get_increase_speed(self):
        """
        获取涨速

        Returns:
            float: 涨速
        """
        return self.increase_speed

    def get_five_minute_change(self):
        """
        获取5分钟涨跌

        Returns:
            float: 5分钟涨跌
        """
        return self.five_minute_change

    def get_sixty_day_change(self):
        """
        获取60日涨跌幅

        Returns:
            float: 60日涨跌幅
        """
        return self.sixty_day_change

    def get_year_to_date_change(self):
        """
        获取年初至今涨跌幅

        Returns:
            float: 年初至今涨跌幅
        """
        return self.year_to_date_change

    # Setter方法
    def set_code(self, code):
        """
        设置股票代码

        Args:
            code (str): 股票代码
        """
        self.code = code

    def set_name(self, name):
        """
        设置股票名称

        Args:
            name (str): 股票名称
        """
        self.name = name

    def set_latest_price(self, latest_price):
        """
        设置最新价

        Args:
            latest_price (float): 最新价
        """
        self.latest_price = latest_price

    def set_change_percent(self, change_percent):
        """
        设置涨跌幅

        Args:
            change_percent (float): 涨跌幅
        """
        self.change_percent = change_percent

    def set_change_amount(self, change_amount):
        """
        设置涨跌额

        Args:
            change_amount (float): 涨跌额
        """
        self.change_amount = change_amount

    def set_volume(self, volume):
        """
        设置成交量

        Args:
            volume (float): 成交量
        """
        self.volume = volume

    def set_turnover(self, turnover):
        """
        设置成交额

        Args:
            turnover (float): 成交额
        """
        self.turnover = turnover

    def set_amplitude(self, amplitude):
        """
        设置振幅

        Args:
            amplitude (float): 振幅
        """
        self.amplitude = amplitude

    def set_high(self, high):
        """
        设置最高价

        Args:
            high (float): 最高价
        """
        self.high = high

    def set_low(self, low):
        """
        设置最低价

        Args:
            low (float): 最低价
        """
        self.low = low

    def set_open_price(self, open_price):
        """
        设置今开盘价

        Args:
            open_price (float): 今开盘价
        """
        self.open_price = open_price

    def set_prev_close(self, prev_close):
        """
        设置昨收盘价

        Args:
            prev_close (float): 昨收盘价
        """
        self.prev_close = prev_close

    def set_volume_ratio(self, volume_ratio):
        """
        设置量比

        Args:
            volume_ratio (float): 量比
        """
        self.volume_ratio = volume_ratio

    def set_turnover_rate(self, turnover_rate):
        """
        设置换手率

        Args:
            turnover_rate (float): 换手率
        """
        self.turnover_rate = turnover_rate

    def set_dynamic_pe_ratio(self, dynamic_pe_ratio):
        """
        设置市盈率-动态

        Args:
            dynamic_pe_ratio (float): 市盈率-动态
        """
        self.dynamic_pe_ratio = dynamic_pe_ratio

    def set_pb_ratio(self, pb_ratio):
        """
        设置市净率

        Args:
            pb_ratio (float): 市净率
        """
        self.pb_ratio = pb_ratio

    def set_total_market_value(self, total_market_value):
        """
        设置总市值

        Args:
            total_market_value (float): 总市值
        """
        self.total_market_value = total_market_value

    def set_circulating_market_value(self, circulating_market_value):
        """
        设置流通市值

        Args:
            circulating_market_value (float): 流通市值
        """
        self.circulating_market_value = circulating_market_value

    def set_increase_speed(self, increase_speed):
        """
        设置涨速

        Args:
            increase_speed (float): 涨速
        """
        self.increase_speed = increase_speed

    def set_five_minute_change(self, five_minute_change):
        """
        设置5分钟涨跌

        Args:
            five_minute_change (float): 5分钟涨跌
        """
        self.five_minute_change = five_minute_change

    def set_sixty_day_change(self, sixty_day_change):
        """
        设置60日涨跌幅

        Args:
            sixty_day_change (float): 60日涨跌幅
        """
        self.sixty_day_change = sixty_day_change

    def set_year_to_date_change(self, year_to_date_change):
        """
        设置年初至今涨跌幅

        Args:
            year_to_date_change (float): 年初至今涨跌幅
        """
        self.year_to_date_change = year_to_date_change

    def get_creation_time(self):
        """
        获取创建时间

        Returns:
            datetime: 创建时间
        """
        return self.creation_time.strftime("%Y-%m-%d %p")   # 格式化时间为上午/下午格式

    def set_creation_time(self, creation_time):
        """
        设置创建时间

        Args:
            creation_time (datetime): 创建时间
        """
        self.creation_time = creation_time


"""
if __name__ == '__main__':
    # 创建一个StockBase对象并设置属性值
    stock = StockBase("001", "股票A", 10.0, 0.05, 0.5, 10000, 1000000, 0.1, 12.0, 9.0, 11.0, 9.5, 1.2, 1.0, 20.0, 2.0, 
                     1000000000, 500000000, 0.2, 0.3, 0.1, 0.05, 0.1)

    # 使用getter获取属性值并打印
    print(stock.get_code())
    print(stock.get_name())
    print(stock.get_latest_price())
    # 使用setter设置属性值
    stock.set_code("002")
    stock.set_name("股票B")
    stock.set_latest_price(15.0)
    # 使用getter验证属性值是否已更新
    print(stock.get_code())
    print(stock.get_name())
    print(stock.get_latest_price())
    
"""
